sexS<-read.csv("train.csv")
library(tidyverse)
#将文本型转化为数值型，男为0，女为1
typeof(sexS)
table(sexS$Sex)
a <- sub("female","1",sexS$Sex)
b <- sub("male","0",a)

sexS$Sex <- b
#查看结构类型
typeof(sexS$Sex)



#sexS$Sex<-as.numeric(sexS$Sex)
sexS$Sex<-as.numeric(as.character(sexS$Sex))
typeof(sexS$Sex)
#简单线性回归，探究性别与获救成功的关系，验证“女士与小孩先走”是否成立
sexS<-lm(Sex~Survived,sexS$Sex)
summary(Sex)
fitted(sexS)
residuals(sexS)
plot(sexS$Sex,sexS$Survived,xlab = "sex",ylab="survived" )
abline(sexS)
